﻿using System;
using System.Collections.Generic;
using System.Text;

namespace zevenseas.Community.Search
{
    public class MOSSSQLSearch
    {
        private WhereStatement where;
        private SortStatement sortStatement;
        private SelectStatement selectStatement;
        private FromStatement fromStatement;

        public FromStatement FromStatement
        {
            get { return fromStatement; }
            set { fromStatement = value; }
        }

        public SelectStatement SelectStatement
        {
            get { return selectStatement; }
            set { selectStatement = value; }
        }

        public SortStatement SortStatement
        {
            get { return sortStatement; }
            set { sortStatement = value; }
        }

        public WhereStatement Where
        {
            get { return where; }
            set { where = value; }
        }

        public MOSSSQLSearch()
        {
            sortStatement = new SortStatement();
            fromStatement = new FromStatement();
        }

        public string ToString(bool formatted)
        {
            StringBuilder sqlStatement = new StringBuilder();

            sqlStatement.AppendLine(selectStatement.ToString().Trim());
            sqlStatement.AppendLine(fromStatement.ToString().Trim());
            sqlStatement.AppendLine(where.ToString().Trim());
            sqlStatement.AppendLine(sortStatement.ToString().Trim());

            return sqlStatement.ToString();                
        }

        public override string ToString()
        {
            StringBuilder sqlStatement = new StringBuilder();

            sqlStatement.Append(selectStatement.ToString());
            sqlStatement.Append(fromStatement.ToString());
            sqlStatement.Append(where.ToString());
            sqlStatement.Append(sortStatement.ToString());

            return sqlStatement.ToString();
        }
    }
}